﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _11_自定义控件
{
    public partial class Frm_EditorNode : Form
    {
        /// <summary>
        /// 节点
        /// </summary>
        public NodeClass Node { get; set; }

        public Frm_EditorNode()
        {
            InitializeComponent();
            //设置默认颜色为黑色
            this.textBox4.Text = Color.Black.Name;
        }

        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog()==DialogResult.OK)
            {
                if (Node != null)
                {
                    Node.NodeColor = colorDialog1.Color;
                }
                else
                {
                    Node = new NodeClass(this.textBox1.Text,int.Parse(this.textBox2.Text), int.Parse(this.textBox3.Text),colorDialog1.Color);
                }
                //显示颜色
                this.textBox4.Text = colorDialog1.Color.Name;
            }
        }
        /// <summary>
        /// 确认按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //判断输入的坐标值与文本不能为空
            if (string.IsNullOrEmpty(this.textBox1.Text) || string.IsNullOrEmpty(this.textBox2.Text) || string.IsNullOrEmpty(this.textBox3.Text))
            {
                MessageBox.Show("请填写完整的信息");
                return;
            }
            Node = new NodeClass(this.textBox1.Text, int.Parse(this.textBox2.Text), int.Parse(this.textBox3.Text), colorDialog1.Color);
            this.DialogResult = DialogResult.OK;
        }
    }
}
